package com.msmall.community.album.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import com.msmall.base.model.BaseObject;
import com.msmall.base.util.ConstantDB;
import com.msmall.base.util.Constants;

/**
 * 相册
 */
@Entity
@Table(name="base_album")
public class Album extends BaseObject{

	private static final long serialVersionUID = -2794480338666178483L;

	@Id
	@Column(name="album_id")
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private Long albumid;
	
	@Column(name="user_id")
	private Long userid;
	
	/**
	 * 相册名
	 */
	@Column(name="title", length=15)
	private String title;
	
	/**
	 * 只提供密码锁方式锁定相册
	 * ConstantDB.UNLOCK_STATUS
	 */
	@Column(name="lock_status")
	private Short lockStatus;
	
	@Column(name="password", length=6)
	private String password;
	
	/**
	 * 相册封面图片ID，如果为null，则使用系统默认图片
	 */
	@Column(name="photo_id")
	private Long photoid;
	
	/**
	 * 相册内包含的照片数
	 */
	@Column(name="counts")
	private Integer counts;
	
	@Column(name="create_time")
	@Temporal(TemporalType.TIMESTAMP)
	private Date createTime;
	
	/**
	 * 上次修改相片的日期
	 */
	@Column(name="last_modify_time")
	@Temporal(TemporalType.TIMESTAMP)
	private Date lastModifyTime;

	/**
	 * 相册封面图片，如果为null，则使用系统默认图片
	 */
	@Transient
	private Photo photo;
	
	public String getCoverPathOwner(){
		return getCoverPath(true);
	}
	public String getCoverPathViewer(){
		return getCoverPath(false);
	}
	/**
	 *  @param isOwner 当前访问者是否是相册所有人
	 */
	public String getCoverPath(boolean isOwner){
		String cover = "";
		if(ConstantDB.LOCK_STATUS.compareTo(lockStatus) == 0){
			if(isOwner){
				if(photo == null){
					cover = ConstantDB.ALBUM_COVER_DEFAULT_FILE_PATH 
							+ Constants.FILE_SEP_HTTP 
							+ ConstantDB.ALBUM_COVER_DEFAULT_FILE_NAME
							+ 
							"." 
							+ ConstantDB.ALBUM_COVER_DEFAULT_FILE_EXT;
				}else{
					cover = photo.getFullPath();
				}
			}else{
				cover = ConstantDB.ALBUM_COVER_DEFAULT_FILE_PATH_LOCKED 
						+ Constants.FILE_SEP_HTTP 
						+ ConstantDB.ALBUM_COVER_DEFAULT_FILE_NAME_LOCKED
						+ 
						"." 
						+ ConstantDB.ALBUM_COVER_DEFAULT_FILE_EXT_LOCKED;
			}
		}else{
			if(photo == null){
				cover = ConstantDB.ALBUM_COVER_DEFAULT_FILE_PATH 
						+ Constants.FILE_SEP_HTTP 
						+ ConstantDB.ALBUM_COVER_DEFAULT_FILE_NAME
						+ 
						"." 
						+ ConstantDB.ALBUM_COVER_DEFAULT_FILE_EXT;
			}else{
				cover = photo.getFullPath();
			}
		}
		return cover;
	}
	public Long getAlbumid() {
		return albumid;
	}

	public void setAlbumid(Long albumid) {
		this.albumid = albumid;
	}

	public Long getUserid() {
		return userid;
	}

	public void setUserid(Long userid) {
		this.userid = userid;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public Short getLockStatus() {
		return lockStatus;
	}

	public void setLockStatus(Short lockStatus) {
		this.lockStatus = lockStatus;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Long getPhotoid() {
		return photoid;
	}

	public void setPhotoid(Long photoid) {
		this.photoid = photoid;
	}

	public Photo getPhoto() {
		return photo;
	}

	public void setPhoto(Photo photo) {
		this.photo = photo;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Date getLastModifyTime() {
		return lastModifyTime;
	}

	public void setLastModifyTime(Date lastModifyTime) {
		this.lastModifyTime = lastModifyTime;
	}

	public Integer getCounts() {
		return counts;
	}
	public void setCounts(Integer counts) {
		this.counts = counts;
	}
	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean equals(Object o) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public int hashCode() {
		// TODO Auto-generated method stub
		return 0;
	}
	
}
